import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;


class SocketClient implements Runnable {

    private PrintWriter out;
    private BufferedReader in;
    private boolean isMessageWaiting = false;



    private String message;

    public void setMessage(String message) {
        this.message = message;
        isMessageWaiting = true;
    }

    SocketClient(String hostName, int portNumber, Player player) throws IOException {
        try (
                Socket socket = new Socket(hostName, portNumber);
                PrintWriter out =
                        new PrintWriter(socket.getOutputStream(), true);
                BufferedReader in =
                        new BufferedReader(new InputStreamReader(socket.getInputStream()));
        ) {

            this.run();

        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection to " +
                    hostName);
            System.exit(1);
        }
    }

    @Override
    public void run() {
            while (true) {
                if(isMessageWaiting) {
                    out.println(message);
                    System.out.println("Sent " + message + " to server.");
                    isMessageWaiting = false;
                }
            }
    }
}